home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / pccp019.zip / TERM.C < prev    next >
Text File  |  1992-05-09  |  20KB  |  976 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  *    MicroSoft QuickC: >qcl term.c graphics.lib
  3.  */
  4.  
  5. #include<stdio.h>
  6. #include<bios.h>
  7. #include<dos.h>
  8. #include<fcntl.h>
  9. #include<graph.h>
  10. #include"emu.h"
  11. #include"color.h"
  12.  
  13. #define DLLSBREG 0
  14. #define DLMSBREG 1
  15. #define INTCTLREG 1
  16. #define INTIDREG 2
  17. #define LCTLREG 3
  18. #define MCTLREG 4
  19. #define STATREG 5
  20.  
  21. #define INTACK 0x20
  22.  
  23. #define DB7 0x02
  24. #define DB8 0x03
  25. #define STOP2 0x04
  26. #define PARITYEN 0x08
  27. #define PARITYEVEN 0x10
  28. #define DLAB 0x80
  29.  
  30. #define INTBASE1 0x20
  31. #define INTMASK1 0x21
  32. #define INTBASE2 0xa0
  33. #define INTMASK2 0xa1
  34.  
  35. #define TBUFSIZ 8192
  36.  
  37. int index, basereg;
  38. unsigned char buf[TBUFSIZ];
  39. unsigned char diffintmask, irqnum;
  40. void (interrupt far *oldvect)();
  41.  
  42. void interrupt far inthndl(_es, _ds, _di, _si, _bp, _sp,
  43.               _bx, _dx, _cx, _ax, _ip, _cs, _flags)
  44.     unsigned _es, _ds, _di, _si, _bp, _sp;
  45.     unsigned _bx, _dx, _cx, _ax, _ip, _cs, _flags;
  46.     {
  47.     if(inp(basereg+STATREG)&0x01)
  48.         {
  49.         buf[index++]=inp(basereg)&0xff;
  50.         index=index%TBUFSIZ;
  51.         }
  52.     outp(INTBASE1, INTACK);
  53.     outp(INTBASE2, INTACK);
  54.     }
  55.  
  56. unsigned char lctl;
  57.  
  58. dispkbd(code)
  59.     unsigned short code;
  60.     {
  61.     int i;
  62.     long tstamp, tstamp1, dayofticksp;
  63.     unsigned char ccode, scode;
  64.     ccode=code&0xff;
  65.     scode=(code>>8)&0xff;
  66.     if(ccode)
  67.         {
  68.         while(!(inp(basereg+STATREG)&0x20));
  69.         outp(basereg, code);
  70.         }
  71.     else
  72.         if(!emu.keys[scode].len)
  73.             putch(0x07);
  74.         else
  75.             for(i=0;i<emu.keys[scode].len;i++)
  76.                 {
  77.                 while(!(inp(basereg+STATREG)&0x20));
  78.                 if(emu.keys[scode].nullpause_p&&!emu.keys[scode].chars[i])
  79.                     {
  80.                     _bios_timeofday(_TIME_GETCLOCK, &tstamp);
  81.                     dayofticksp=0;
  82.                     while(1)
  83.                         {
  84.                         if(_bios_timeofday(_TIME_GETCLOCK, &tstamp1))
  85.                             dayofticksp+=20*60*60*24;
  86.                         if(tstamp1+dayofticksp-tstamp>22)
  87.                             break;
  88.                         }
  89.                     }
  90.                 else if(emu.keys[scode].nullpause_p&&(emu.keys[scode].chars[i]==0xff))
  91.                     {
  92.                     _bios_timeofday(_TIME_GETCLOCK, &tstamp);
  93.                     outp(basereg+LCTLREG, lctl|0x40);
  94.                     dayofticksp=0;
  95.                     while(1)
  96.                         {
  97.                         if(_bios_timeofday(_TIME_GETCLOCK, &tstamp1))
  98.                             dayofticksp+=20*60*60*24;
  99.                         if(tstamp1+dayofticksp-tstamp>10)
  100.                             break;
  101.                         }
  102.                     outp(basereg+LCTLREG, lctl);
  103.                     }
  104.                 else
  105.                     outp(basereg, emu.keys[scode].chars[i]);
  106.                 }
  107.     }
  108.  
  109. #define LISTSIZ 16
  110.  
  111. struct
  112.     {
  113.     short index;
  114.     short row;
  115.     short column;
  116.     short list[LISTSIZ];
  117.     short listindex;
  118.     }
  119.     funcstor[NFUNCS];
  120.  
  121. clrfuncstor(seqn)
  122.     short seqn;
  123.     {
  124.     int i;
  125.     for(i=funcstor[seqn].listindex-1;i>=0;i--)
  126.         funcstor[seqn].list[i]=0;
  127.     funcstor[seqn].row=funcstor[seqn].column=funcstor[seqn].listindex=funcstor[seqn].index=0;
  128.     }
  129.  
  130. int bold, faint, blink, inverse, bkcolor, fgcolor;
  131. struct videoconfig far *vconf;
  132.  
  133. atthndl()
  134.     {
  135.     int adds, workingbk, workingfg;
  136.     adds=0;
  137.     if(vconf->adapter!=_MDPA)
  138.         {
  139.         workingbk=bkcolor;
  140.         workingfg=fgcolor;
  141.         if(faint)
  142.             if(inverse)
  143.                 if(bkcolor==WHITE)
  144.                     workingbk=GRAY;
  145.                 else
  146.                     adds+=FAINTADD;
  147.             else
  148.                 if(fgcolor==WHITE)
  149.                     workingfg=GRAY;
  150.                 else
  151.                     adds+=FAINTADD;
  152.         else
  153.             if(bold)
  154.                 {
  155.                 if(bkcolor==WHITE)
  156.                     workingbk=BWHITE;
  157.                 if(fgcolor==WHITE)
  158.                     workingfg=BWHITE;
  159.                 }
  160.         if(blink)
  161.             adds+=BLINKADD;
  162.         if(inverse)
  163.             {
  164.             if(blink)
  165.                 _settextcolor(workingbk+BLINKADD);
  166.             else
  167.                 _settextcolor(workingbk);
  168.             if(faint)
  169.                 _setbkcolor((long)(workingfg+FAINTADD));
  170.             else
  171.                 _setbkcolor((long)workingfg);
  172.             }
  173.         else
  174.             {
  175.             _settextcolor(workingfg+adds);
  176.             _setbkcolor((long)workingbk);
  177.             }
  178.         }
  179.     else
  180.         {
  181.         workingbk=BLACK;
  182.         if(bold&&!inverse)
  183.             workingfg=M_UNDER;
  184.         else
  185.             if(inverse)
  186.                 workingfg=WHITE;
  187.             else
  188.                 workingfg=M_NORMAL;
  189.         if(faint)
  190.             adds+=FAINTADD;
  191.         if(blink)
  192.             adds+=BLINKADD;
  193.         if(inverse)
  194.             {
  195.             if(blink)
  196.                 _settextcolor(workingbk+BLINKADD);
  197.             else
  198.                 _settextcolor(workingbk);
  199.             _setbkcolor((long)workingfg);
  200.             }
  201.         else
  202.             {
  203.             _settextcolor(workingfg+adds);
  204.             _setbkcolor((long)workingbk);
  205.             }
  206.         }
  207.     }
  208.  
  209.  
  210. ansiatthndl(seqn)
  211.     short seqn;
  212.     {
  213.     int i, adds, workingbk, workingfg;
  214.     if(emu.funcs[seqn].func==ANSIATTRIB)
  215.         for(i=0;i<funcstor[seqn].listindex;i++)
  216.             switch(funcstor[seqn].list[i])
  217.                 {
  218.                 /*at the moment this is strictly ANSI subset*/
  219.                 case 0:
  220.                     bkcolor=BLACK;
  221.                     fgcolor=WHITE;
  222.                     bold=faint=blink=inverse=0;
  223.                     break;
  224.                 case 1:
  225.                     bold=1;
  226.                     break;
  227.                 case 2:
  228.                     faint=1;
  229.                     break;
  230.                 case 5:
  231.                 case 6:
  232.                     blink=1;
  233.                     break;
  234.                 case 7:
  235.                     inverse=1;
  236.                     break;
  237.                 case 8:
  238.                 case 30:
  239.                 case 40:
  240.                     fgcolor=bkcolor;
  241.                     break;
  242.                 case 31:
  243.                 case 41:
  244.                     fgcolor=RED;
  245.                     break;
  246.                 case 32:
  247.                 case 42:
  248.                     fgcolor=GREEN;
  249.                     break;    
  250.                 case 33:
  251.                 case 43:
  252.                     fgcolor=YELLOW;
  253.                     break;
  254.                 case 34:
  255.                 case 44:
  256.                     fgcolor=BLUE;
  257.                     break;
  258.                 case 35:
  259.                 case 45:
  260.                     fgcolor=MAGENTA;
  261.                     break;
  262.                 case 36:
  263.                 case 46:
  264.                     fgcolor=CYAN;
  265.                     break;
  266.                 case 37:
  267.                 case 47:
  268.                     fgcolor=WHITE;
  269.                     break;
  270.                 default:
  271.                     break;
  272.                 }
  273.     atthndl();
  274.     }
  275.  
  276. int wrap_p;
  277.  
  278. wrapctl()
  279.     {
  280.     if(wrap_p)
  281.         _wrapon(_GWRAPON);
  282.     else
  283.         _wrapon(_GWRAPOFF);
  284.     }
  285.  
  286. unsigned int speed, comnum;
  287. char databits, parity, stopbits, fpname[256], dribpname[256];
  288.  
  289. updstatus()
  290.     {
  291.     struct rccoord posptr;
  292.     short tc;
  293.     long bc;
  294.     char str[80];
  295.     posptr=_gettextposition();
  296.     tc=_gettextcolor();
  297.     bc=_getbkcolor();
  298.     _settextwindow(1,1,1,80);
  299.     _settextposition(1,1);
  300.     _settextcolor(BLACK);
  301.     _setbkcolor((long)WHITE);
  302.     _wrapon(_GWRAPOFF);
  303.     sprintf(str, "Both Shifts to Exit COM%u %5u %c%c%c %22s %22s",
  304.         comnum+1, speed, databits, parity, stopbits, fpname, dribpname);
  305.     _outtext(str);
  306.     _settextwindow(2,1,25,80);
  307.     wrapctl();
  308.     _settextcolor(tc);
  309.     _setbkcolor(bc);
  310.     _settextposition(posptr.row, posptr.col);
  311.     }
  312.  
  313. int graphics;
  314.  
  315. showchar(c)
  316.     char c;
  317.     {
  318.     char str[2];
  319.     if(graphics)
  320.         if(emu.gchars[c])
  321.             c=emu.gchars[c];
  322.     str[0]=c;
  323.     str[1]='\0';
  324.     _outtext(str);
  325.     }
  326.  
  327. perffunc(seqn)
  328.     short seqn;
  329.     {
  330.     struct rccoord posptr;
  331.     int i;
  332.     switch(emu.funcs[seqn].func)
  333.         {
  334.         case CLEAR:
  335.             _clearscreen(_GCLEARSCREEN);
  336.             updstatus();
  337.             _settextposition(1,1);
  338.             break;
  339.         case HOME:
  340.             _settextposition(1,1);
  341.             break;
  342.         case CLREOL:
  343.             posptr=_gettextposition();
  344.             _wrapon(_GWRAPOFF);
  345.             for(i=posptr.col;i<=80;i++)
  346.                 _outtext(" ");
  347.             _settextposition(posptr.row, posptr.col);
  348.             wrapctl();
  349.             break;
  350.         case UP:
  351.             posptr=_gettextposition();
  352.             if(posptr.row>1)
  353.                 _settextposition(posptr.row-1, posptr.col);
  354.             break;
  355.         case DOWN:
  356.             posptr=_gettextposition();
  357.             if(posptr.row<24)
  358.                 _settextposition(posptr.row+1, posptr.col);
  359.             else
  360.                 {
  361.                 showchar('\n');
  362.                 _settextposition(posptr.row, posptr.col);
  363.                 }
  364.             break;
  365.         case LEFT:
  366.             posptr=_gettextposition();
  367.             if(posptr.col>1)
  368.                 _settextposition(posptr.row, posptr.col-1);
  369.             break;
  370.         case RIGHT:
  371.             posptr=_gettextposition();
  372.             if(posptr.col<80)
  373.                 _settextposition(posptr.row, posptr.col+1);
  374.             break;
  375.         case GOTO:
  376.             if(funcstor[seqn].row<1)
  377.                 funcstor[seqn].row=1;
  378.             if(funcstor[seqn].row>24)
  379.                 funcstor[seqn].row=24;
  380.             if(funcstor[seqn].column<1)
  381.                 funcstor[seqn].column=1;
  382.             if(funcstor[seqn].column>80)
  383.                 funcstor[seqn].row=80;
  384.             _settextposition((emu.tophi_p?25-funcstor[seqn].row:funcstor[seqn].row), funcstor[seqn].column);
  385.             break;
  386.         case NORMAL:
  387.             fgcolor=WHITE;
  388.             bkcolor=BLACK;
  389.             blink=faint=bold=inverse=0;
  390.             atthndl();
  391.             break;
  392.         case BLINK:
  393.             blink=1;
  394.             atthndl();
  395.             break;
  396.         case NOBLINK:
  397.             blink=0;
  398.             atthndl();
  399.             break;
  400.         case BOLD:
  401.             bold=1;
  402.             atthndl();
  403.             break;
  404.         case NOBOLD:
  405.             bold=0;
  406.             atthndl();
  407.             break;
  408.         case FAINT:
  409.             faint=1;
  410.             atthndl();
  411.             break;
  412.         case NOFAINT:
  413.             faint=0;
  414.             atthndl();
  415.             break;
  416.         case INVERSE:
  417.             inverse=1;
  418.             atthndl();
  419.             break;
  420.         case NOINVERSE:
  421.             inverse=0;
  422.             atthndl();
  423.             break;
  424.         case UPN:
  425.             posptr=_gettextposition();
  426.             if(posptr.row-funcstor[seqn].row<1)
  427.                 _settextposition(1, p